package com.sxkf.template.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sxkf.core.constant.CommonConstant;
import com.sxkf.template.entity.UserCoupon;
import com.sxkf.template.service.UserCouponService;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

@Configuration
@Transactional
public class UserCouponJob {
    @Resource
    private UserCouponService userCouponService;

    @Scheduled(cron = "0 0 1 * * ?")
    public void updateUserCoupon() {
        userCouponService.update(new LambdaUpdateWrapper<UserCoupon>()
                .set(UserCoupon::getState, CommonConstant.EXPIRE)
                .eq(UserCoupon::getState,CommonConstant.ENABLE)
                .le(UserCoupon::getCloseTime,new Date())
        );
    }
}
